//
//  CycleTool+CreateProperty.m
//  CDSBZX
//
//  Created by dihuijun on 17/3/31.
//  Copyright © 2017年 Cycle. All rights reserved.
//

#import "CycleTool+CreateProperty.h"

@implementation CycleTool (CreateProperty)
/**
 *  根据字典生成对于的属性代码块
 */
+ (void)cycle_createPropertyWithDict:(NSDictionary *)dict{
    
    NSMutableString *strMProperty = [NSMutableString string];
    //遍历字典
    [dict enumerateKeysAndObjectsUsingBlock:^(id  _Nonnull propertyName, id  _Nonnull value, BOOL * _Nonnull stop) {
       /*
        propertyName(key):属性名
        value(obj)       : 属性名对应的类型
        */
        NSString *code;
        NSLog(@"代码块字段类型: %@",[value class]);
        
        if ([value isKindOfClass:NSClassFromString(@"__NSCFString")]) {
            code = [NSString stringWithFormat:@"@property (nonatomic, copy) NSString *%@;",propertyName];
        }else if ([value isKindOfClass:NSClassFromString(@"__NSCFNumber")]){
            code = [NSString stringWithFormat:@"@property (nonatomic, assign) int %@;",propertyName];
        }else if ([value isKindOfClass:NSClassFromString(@"__NSCFArray")]){
            code = [NSString stringWithFormat:@"@property (nonatomic, strong) NSArray *%@;",propertyName];
        }else if ([value isKindOfClass:NSClassFromString(@"__NSCFDictionary")]){
            code = [NSString stringWithFormat:@"@property (nonatomic, strong) NSDictionary *%@;",propertyName];
        }else if ([value isKindOfClass:NSClassFromString(@"__NSCFBoolean")]){
            code = [NSString stringWithFormat:@"@property (nonatomic, assign) BOOL %@;",propertyName];
        }
        
        [strMProperty appendFormat:@"\n%@\n",code];
        
    }];
    NSLog(@"\n最后生成的模型块：\n %@",strMProperty);
    
}
@end
